import 'reflect-metadata'

@Reflect.metadata('k', 'v')
class Project {

  @Reflect.metadata('k', 'v')
  projectId!: number;

  @Reflect.metadata('k', 'v')
  framworkId!: string;

  @Reflect.metadata('k', 'v')
  projectName!: string;

  @Reflect.metadata('k', 'v')
  createAt!: Date;

  @Reflect.metadata('k', 'v')
  updateAt!: Date;
}

const array: Project[] = [];

let countG: number = 0;
const init = (count: number) => {
  countG = count;
  for (let i = 0; i < count; i++) {
    const p = new Project();
    p.projectId = i;
    p.framworkId = `framworkId-${i}`;
    p.projectName = `projectName-${i}`;
    p.createAt = new Date();
    p.updateAt = new Date();
    array.push(p);
  }
}

const test = () => {
  for (const p of array) {
    // @ts-ignore
    let type = Reflect.getMetadata("design:type", (<any>p).__proto__, "projectId");
    // console.log("projectId\t\t", type?.name);
    type = Reflect.getMetadata("design:type", (<any>p).__proto__, "framworkId");
    // console.log("framworkId\t\t", type?.name);
    type = Reflect.getMetadata("design:type", (<any>p).__proto__, "projectName");
    // console.log("projectName\t\t", type?.name);
    type = Reflect.getMetadata("design:type", (<any>p).__proto__, "createAt");
    // console.log("createAt\t\t", type?.name);
    type = Reflect.getMetadata("design:type", (<any>p).__proto__, "updateAt");
    // console.log("updateAt\t\t", type?.name);
  }
}

init(100000);
const sTime = new Date().getTime();
test();
const eTime = new Date().getTime();
console.log("耗时:", (eTime - sTime), "ms | 速度:", (eTime - sTime) / countG, "ms/次 | ", countG / (eTime - sTime), "次/ms")

// -------------------------------------------------------------------------------------------------------------------------------------

export class SomeClass {
  @Prop()
  public prop!: Project;
}

// @ts-ignore
let targetG: any;

export function Prop(): PropertyDecorator {
  return (target, key: string | symbol) => {
    targetG = target;
    const type = Reflect.getMetadata('design:type', target, key);
    console.log(`${<string>key} type: ${type.name}`);
  };
}

const type = Reflect.getMetadata('design:type', targetG, "prop");
console.log("### type --> ", type?.name);

export {
  init,
  test,
}
